package com.it.controller;


import com.it.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

// TODO SpringMVC (2)、返回JSON数据

// @Controller
@RequestMapping("/json")
// @ResponseBody
@RestController // 相当于 添加了 @Controller和 @ResponseBody
public class springmvc02 {

    /**
     *  返回实体类： /json/data1
     */
    @GetMapping("/data1")
    public User data1() {
        User user = new User();
        user.setName("zhangsan");
        user.setAge(20);
        return user;
    }

    /**
     * 返回集合
     */
    @GetMapping("/data2")
    public List<User> data2() {
        User user = new User();
        List<User> list = new ArrayList<User>();
        user.setName("lisi");
        user.setAge(30);
        list.add(user);
        return list;
    }


}
